07. Maven Projects

Maven Projects

ND079 JPND C3 L2 A05 Maven Projects

Pom.xml

Each Maven project is defined by a file called pom.xml. This stands for Project Object Model. The Pom has 4 required elements:

  • modelVersion: The format of the current pom. Should always be 4.0.0 at this time.
  • groupId: The group identifier for your project. Can be shared with other projects.
  • artifactId: The specific identifier for this project. Combination of artifactId and groupId uniquely identifies your project.
  • version: An arbitrary additional identifier indicating which version of your artifact you're on. By incrementing this, you can use can use Maven to keep track of different versions of your project.

Minimal pom.xml

<project>
  <modelVersion> 4.0.0 </modelVersion>

  <groupId> com.udacity.jpnd </groupId>
  <artifactId> maven-test </artifactId>
  <version> 1.0.0 </version>
</project>

Maven Phases and pom.xml

You can run maven by using the mvn command followed by the phase you wish to run. In our demo, we created the above minimal pom.xml in a directory and then ran the package command to build our project:

mvn package

Creating a Maven Project

ND079 JPND C3 L2 A06 Creating A Maven Project V2

Creating a New Maven Project

You can create Maven projects using the archetype:generate goal. You can run this goal from the command line or through an IDE wizard.

To use generate a new project from the command line:

  1. Use the command mvn archetype:generate
  2. Press enter to accept the default template, which is the maven quickstart project.
  3. Press enter again to accept the newest version of the quickstart template.
  4. Fill in the required elements of a minimal pom.

Maven will create a new project directory with a pom.xml some starter source code and test directories.